package com.it.service.impl;

import com.it.entity.worker.SystemMenu;
import com.it.entity.worker.SystemUser;
import com.it.mapper.SystemMenuMapper;
import com.it.mapper.SystemRoleMapper;
import com.it.mapper.SystemUserMapper;
import com.it.service.SystemMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import utils.R;

import java.util.List;

/**
 * <p>
 * 系统菜单表（农业保险系统） 服务实现类
 * </p>
 *
 * @author sunwz
 * @since 2025年09月15日
 */
@Service
public class SystemMenuServiceImpl extends ServiceImpl<SystemMenuMapper, SystemMenu> implements SystemMenuService {

    @Autowired
    private SystemMenuMapper systemMenuMapper;

    @Autowired
    private SystemRoleMapper systemRoleMapper;

    @Autowired
    private SystemUserMapper systemUserMapper;

    @Override
    public R getMenu(String id) {
        // 查询当前用户
        SystemUser user = systemUserMapper.selectById(id);
        // 一级菜单数据
        List<SystemMenu> systemMenus = systemMenuMapper.getMenu(user.getRoleId(),0);
        // 查询对应的子菜单
        systemMenus.forEach(systemMenu -> {
            // 二级菜单数据
            List<SystemMenu> systemMenus0 = systemMenuMapper.getMenu(user.getRoleId(),systemMenu.getId());
            systemMenu.setSystemMenus(systemMenus0);
        });
        return R.Success("查询成功", systemMenus);
    }
}
